﻿using System.Linq;
using System;

namespace RakutenCrawler.Repository
{
    public class ProductCategoryRepository : GenericRepository<ProductCategory>
    {
        public ProductCategoryRepository():base()
        {

        }

        public ProductCategoryRepository(bool lazyLoad):base(lazyLoad)
        {

        }

        public override void InsertOrUpdate(ProductCategory item)
        {
            var check = All.FirstOrDefault(p => p.ProductCategoryURL == item.ProductCategoryURL || p.ProductCategoryId == item.ProductCategoryId);
            if (check == null)
            {
                item.InsertedDate = DateTime.Now;
                All.AddObject(item);
            }
            else
            {
                item.ProductCategoryId = check.ProductCategoryId;
                item.InsertedDate = check.InsertedDate;
                All.ApplyCurrentValues(item);
            }
        }
    }
}
